const typescript = require('rollup-plugin-typescript2');
const tslint = require('rollup-plugin-tslint');
const terser = require('rollup-plugin-terser').terser;
const pkg = require('./package.json');

const plugins = (tsConfig = {}) => [
  tslint(),
  typescript({
    tsconfig: 'tsconfig.json',
    tsconfigOverride: tsConfig,
    typescript: require('typescript'),
    cacheRoot: './tmp/.rts2_cache',
    useTsconfigDeclarationDir: true,
    include: ["src/**/*.ts"],
  }),
];

const banner = '/*!\n' +
  ` * ${pkg.name} v${pkg.version} | ${pkg.author.email}\n` +
  ` * (c) ${new Date().getFullYear()} ${pkg.author.name}(${pkg.author.email}) | Released under the MIT license\n` +
  ' */\n';

export default [
  // UMD unminified
  {
    input: 'src/canvas.ts',
    plugins: [
      ...plugins({
        compilerOptions: {
          target: 'ES5',
        },
      }),
    ],
    output: {
      file: 'dist/canvas.umd.js',
      format: 'umd',
      name: 'Canvas',
      banner,
    },
    watch: {
      include: 'src/**'
    }
  },

  // UMD minified
  {
    input: 'src/canvas.ts',
    plugins: [
      ...plugins({
        compilerOptions: {
          target: 'ES5',
        },
      }),
      terser()
    ],
    output: {
      file: 'dist/canvas.umd.min.js',
      format: 'umd',
      name: 'Canvas',
      banner,
    },
    watch: {
      include: 'src/**'
    }
  },
];
